import { ref } from 'vue'
import { defineStore } from 'pinia'
import { useUserStore } from "@/stores/userStore.js";
import {getFriends} from "@/api/friend.js";

export const useFriendStore = defineStore('friendStore', () => {
    const friendList = ref([])

    const storeGetFriendList = async () => {
        const res = await getFriends(useUserStore().userInfo?.id)
        if (res.status === 200) {
            friendList.value = res.data
        }
    }

    const addFriend = (data) => {
        friendList.value.push(data)
    }

    const setFriendList = (list) => {
        friendList.value = list
    }
    return {friendList, addFriend, storeGetFriendList, setFriendList}
})
